package threading;

public class Demo20 {
    public static void main(String[] args) throws InterruptedException{
        Object object = new Object();
        Thread t1 = new Thread(()-> {
            while (true) {
                synchronized (object) {
                    System.out.println("wait1 之前");
                    try {
                        object.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    System.out.println("wait1 之后");
                }

            }
        });

        t1.start();
        Thread.sleep(500);
        Thread t3 = new Thread(()-> {
            while (true) {
                synchronized (object) {
                    System.out.println("wait 3 之前");
                    try {
                        object.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    System.out.println("wait 3 之后");
                }

            }
        });

        t3.start();

        Thread.sleep(500);

        Thread t2 = new Thread(()-> {
           while(true) {

               synchronized (object) {
                   System.out.println("notify之前");
                   object.notify();
                   System.out.println("notify 之后");
               }
               try {
                   Thread.sleep(3000);
               } catch (InterruptedException e) {
                   e.printStackTrace();
               }

           }
        });

        t2.start();

    }
}
